package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import org.joda.time.DateTime

abstract class DtenAskNowData(_len: Int) : D10BaseData(_len) {
    var good = true

    var sampleTimeBcd: BcdString? = null

    var sampleTime: DateTime? = null
        get() = if (sampleTimeBcd?.size != 5) null
        else DateTime(sampleTimeBcd!!.bcdArray!![0] + DateTime.now().year.div(100).times(100),
                sampleTimeBcd!!.bcdArray!![1].toInt(),
                sampleTimeBcd!!.bcdArray!![2].toInt(),
                sampleTimeBcd!!.bcdArray!![3].toInt(),
                sampleTimeBcd!!.bcdArray!![4].toInt())
        set(value) {
            field = value
            sampleTimeBcd = if (field == null) null
            else BcdString(byteArrayOf(field!!.year.rem(100).toByte(),
                    field!!.monthOfYear.toByte(),
                    field!!.dayOfMonth.toByte(),
                    field!!.hourOfDay.toByte(),
                    field!!.minuteOfHour.toByte()), true)
        }

    var internalAddr: Byte? = null

    var reading: Float? = null
}